#include <stdio.h>
#include <stdlib.h>

#define MAXLEN 512

int main()
{
    char buf[11]={0};
    char *p = (char *)malloc(sizeof(char) * MAXLEN);
    if(p == NULL)
    {
        perror("malloc failed!");
        exit(-1);
    }

    p = fgets(p, MAXLEN, stdin);

    if(p == NULL)
    {
        perror("fgets failed!");
        exit(-1);
    }
    sprintf(buf, "%10s", p);
    printf("you inputed: %s\nbuf now is: %s", p, buf);

    if(p != NULL)
    {
        free(p);
    }

    return 0;
}
